import "./scss/test.scss";

require('./utils/jquery')
const limit = 750
function randomUid (length) {
  const counts = [1,2,3,4,5,6,7,8,9]
  
  const targets = []
  for (let i = 0; i<length; i++) {
    targets.push(counts[Math.floor(Math.random() * 9)])
  }
  return targets.join('')
}
$(window).load(function(){
  let w = $(this).width() > limit ? limit:  $(this).width()
  $('.card1').css({ width: w + 'px'})
  let leng = $('.card1').length
  $(".box").attr({
    'data-width': (w * leng) + 'px',
  })
  $(".box").css({
    'width': (w * leng) + 'px',
  })
  $(".box").addClass('ant')
  $("#idCode").text(randomUid(8))
})
$(".box .card1 .btn").click(function(){
  let l = $(this).parents('.card1').index()
  let leng = $('.card1').length
  let win = $(".box").data('width')
  let isYes = $(this).hasClass('yes')
  if (l+1 == leng) {
    return
  }
  try {
    gtag('event', 'click', {
      'question': l + 1,
      'click': isYes ? 'yes' : 'no'
    });
  } catch (e) {
    console.log(e)
  }
 
  $(".box").attr({style: `transform: translateX(-${(l+1)/leng * 100}%);width: ${win}`})
  
})


